package com.shirley.pers.zhufengfmvi.entities;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Description: 专辑详情曲目列表信息<br/>
 * <p/>
 * Copyright (c) , 2016, Shirley Xian <br/>
 * This program is protected by copyright laws. <br/>
 * ClassName: AlbumsDetailTracks<br/>
 * Date: 2016/4/8 13:18
 *
 * @author Shirley Xian
 * @version 1.0
 */
public class AlbumsDetailTracks {

    /**
     * list : []
     * pageId : 1
     * pageSize : 2
     * maxPageId : 204
     * totalCount : 407
     */

    private long pageId;
    private long pageSize;
    private long maxPageId;
    private long totalCount;
    private List<Track> list;

    public long getPageId() {
        return pageId;
    }

    public long getPageSize() {
        return pageSize;
    }

    public long getMaxPageId() {
        return maxPageId;
    }

    public long getTotalCount() {
        return totalCount;
    }

    /**
     * 可能为Null
     *
     * @return
     */
    public List<Track> getList() {
        return list;
    }

    public void parseJson(JSONObject jsonObject) throws JSONException {
        if (jsonObject != null) {
            pageId = jsonObject.optLong("pageId");
            pageSize = jsonObject.optLong("pageSize");
            maxPageId = jsonObject.optLong("maxPageId");
            totalCount = jsonObject.optLong("totalCount");
            JSONArray array = jsonObject.getJSONArray("list");
            if (array != null) {
                list = new ArrayList<>();
                for (int i = 0; i < array.length(); i++) {
                    JSONObject jo = array.getJSONObject(i);
                    Track track = new Track();
                    track.parseJson(jo);
                    list.add(track);
                }
            }
        }

    }

}
